package day05.shuzu;

public class Lian01 {
    public static void main(String[] args) {
        int[] arr = {3, 5, 2, 1, 4};
//        -1是为了让索引不超出范围
        for (int i = 0; i < arr.length-1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        add(arr);
        for (int i = 0; i < arr.length-1-1; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        add(arr);
        for (int i = 0; i < arr.length-1-2; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        add(arr);
        for (int i = 0; i < arr.length-1-3; i++) {
            if (arr[i] > arr[i + 1]) {
                int temp = arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=temp;
            }
        }
        add(arr);
    }

    private static void add(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
            System.out.println();
        }
    }

}
